package com.xxx.server508.rabbitmq;

import com.xxx.server508.config.RabbitmqConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 编写一个类用于消费消息
 */
@Component
@Slf4j
public class MessageReceiver {
    @RabbitHandler
    @RabbitListener(queues = RabbitmqConfig.DLK_QUEUE)
    public void onMessage(Message message){
        SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        log.info("使用死信队列，收到消息:{},当前时间为："+format.format(new Date()),new String(message.getBody()));
    }

//    @RabbitHandler
//    @RabbitListener(queues = RabbitmqConfig.DMP_QUEUE)
//    public void onMessage2(Message message){
//        log.info("使用延迟插件，收到消息:{}",new String(message.getBody()));
//    }
}
